package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.common.log.annotation.Log;
import com.share.common.log.enums.BusinessType;
import com.share.common.security.annotation.RequiresPermissions;
import com.share.device.domain.CabinetType;
import com.share.device.service.ICabinetTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/10/10 上午10:02
 */
@Tag(name = "柜机类型接口管理")
@RestController
@RequestMapping("/cabinetType")
@RequiredArgsConstructor
public class CabinetTypeController extends BaseController {

    private final ICabinetTypeService cabinetTypeService;

    /**
     * 获取柜机类型详细信息
     *
     * @param id
     * @return
     */
    @Operation(summary = "获取柜机类型详细信息")
    @RequiresPermissions("device:cabinetType:query")
    @Log(title = "柜机类型")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return success(cabinetTypeService.getById(id));
    }

    /**
     * 添加柜机类型
     *
     * @param cabinetType
     * @return
     */
    @Operation(summary = "添加柜机类型")
    @RequiresPermissions("device:cabinetType:add")
    @Log(title = "柜机类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CabinetType cabinetType) {
        return toAjax(cabinetTypeService.saveCabinetType(cabinetType));
    }

    /**
     * 修改柜机类型
     *
     * @param cabinetType
     * @return
     */
    @Operation(summary = "修改柜机类型")
    @RequiresPermissions("device:cabinetType:edit")
    @Log(title = "柜机类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult update(@RequestBody CabinetType cabinetType) {
        return toAjax(cabinetTypeService.updateCabinetType(cabinetType));
    }

    /**
     * 删除柜机类型信息
     *
     * @param ids
     * @return
     */
    @Operation(summary = "删除柜机类型")
    @RequiresPermissions("device:cabinetType:remove")
    @Log(title = "柜机类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        return toAjax(cabinetTypeService.removeBatchByIds(ids));
    }

    /**
     * 查询全部的柜机类型列表
     *
     * @return
     */
    @Operation(summary = "查询全部可用的柜机类型")
    @Log(title = "柜机类型")
    @GetMapping("/getCabinetTypeList")
    public AjaxResult getCabinetTypeList() {
        return success(cabinetTypeService.getAvailableCabinetTypes());
    }

    /**
     * 查询柜机类型列表
     *
     */
    @Operation(summary = "查询柜机类型列表")
    @RequiresPermissions("device:cabinetType:list")
    @Log(title = "柜机类型")
    @GetMapping("/list")
    public TableDataInfo list(CabinetType cabinetType) {
        //封装分页参数数据
        startPage();
        //调用service查询数据库
        List<CabinetType> list = cabinetTypeService.selectCabinetTypeList(cabinetType);
        return getDataTable(list);
    }

    @PutMapping("/updateStatus")
    @Operation(summary = "修改柜机类型状态")
    public AjaxResult updateStatus(@RequestParam Long id, @RequestParam String status) {
        int result = cabinetTypeService.updateStatus(id, status);
        return success(result);
    }

}
